#include"../include/fun.h"

list::list(){
    head = nullptr;
    length = 0;
};

void list::insert(int x){
    listnode* cur = new listnode(x);
    cur->next = head;
    head = cur;
    ++length; 
};

void list::remove(int x){
    if(length==0) return;
    
    listnode* p = head;
    if(p->data == x){
        head = p->next;
        length --;
        return;
    }
    listnode* q = p->next;
    while(q){
        if(q->data == x){
            p->next = q->next;
            length --;
            delete q;
            q = p->next;
        }
        else{
            p = p->next;
            q = q->next;
        }
    }
};

int list::len(){
    return length;
};

